import java.sql.*;

/******************************************************************************
 * The <code>ChatDB</code> class stores chat information.
 * Methods are provided to access the data.
 * @author Edward McIntyre
 * @version 1.0.0
 *****************************************************************************/
public class ChatDB extends DB
{

    /***************************************************************************
     * Creates a <code>ChatDB</code> object
     **************************************************************************/
    public ChatDB()
    {
        super();
    }

    /***************************************************************************
     * Adds a new message to the system.
     * @param user A <code>String</code> specifying sending user.
     * @param mssg A <code>String</code> specifying the message being sent.
     **************************************************************************/
    public void sendMessage(String user, String mssg)
    {
        String q = "insert into message ";
        q+= "values ";
        q+= "(null, '" + user + "', '" + mssg + "');";
 //       System.out.println("q=" + q);
        doUpdate( q );
    }

    /***************************************************************************
     * Checks database for a new message
     * @param index An <code>int</code> specifying the index of the current message
     * @param user A <code>String</code> specifying the desired user message to be retrieved.
     **************************************************************************/
    public ResultSet getMessage() throws Exception
    {
            String q = "select * from message ";
            ResultSet rs = doQuery( q );
            return rs;
    }

    /***************************************************************************
     * Test of the ChatDB class.
     * @param args A <code>String array</code> not used by this application.
     **************************************************************************/
    public static void main(String[] args) throws Exception
    {

		ChatDB db = new ChatDB();
		db.sendMessage("Scott","TEST");
		ResultSet rs = db.getMessage();
		while(rs.next())
			{
				System.out.println(rs.getString(2) + ": " + rs.getString(3) );
			}
    }
}

